from main.model.logic.interruption import Interruption
from abc import ABCMeta, abstractmethod

class AbstractCPUController(object):
    __metaclass__ = ABCMeta
    @abstractmethod
    def cycle(self):
        raise NotImplementedError
    @abstractmethod
    def reset(self):
        self.__current = 0

class DumyCPUController(AbstractCPUController):

    def cycle(self):
        pass
    
    def reset(self):
        pass


class RRCPUController(AbstractCPUController):
    
    def __init__(self, cpu, maximun=3):
        self.__max = maximun
        self.__current = 0
        self.__cpu = cpu
    
    def cycle(self):  
        self.__current += 1
        if(self.__max < self.__current):
            self.__cpu.trigger(Interruption.TIME_OUT)
            
    def reset(self):
        self.__current = 0
            
    @property
    def max(self): return self.__max
    
    @max.setter
    def max(self, value): self.__max = value
            